package teset;

import java.util.List;

import org.junit.Ignore;
import org.junit.Test;

import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.c3p0.C3p0Plugin;

import util.JFinalUtils;

public class JfinalTest {

	@Test
	@Ignore
	public void test(){
		PropKit.use("jfinal/main.properties");
		String url = PropKit.get("db_url");
		String name = PropKit.get("db_username");
		String pwd = PropKit.get("db_password");
		C3p0Plugin cp = new C3p0Plugin(url, name, pwd);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
//		_MappingKit.mapping(arp);
		cp.start();
		arp.start();
		
		List<Record> list = null;
		StringBuilder sbb = new StringBuilder();
		sbb.append(" SELECT  b.org_id, b.app_secret, b.token, b.sys_id,c.version, a.api_id,a.app_pub_id,a.app_sub_id");
		sbb.append(" FROM api_sub_interface a LEFT JOIN api_app b ON a.app_sub_id = b.app_id");
		sbb.append(" LEFT JOIN api_interface c ON a.api_id = c.api_id");
		sbb.append(" WHERE a.api_id = 'crc.crtsys.JustTest.rs01test0406'");
		sbb.append(" AND a.app_sub_id = '0000000101SP' AND a.del_flag = 0 AND b.del_flag = 0");
		String sql = sbb.toString();
		list = Db.find(sql);
		if(null != list){
			for(Record rd : list){
				System.out.println( rd.get("org_id") );
				System.out.println( rd.get("app_secret") );
			}
		}
	}
	
	@Test
	@Ignore
	public void test2(){
		List<Record> list = JFinalUtils.fetchApiInfo("crc.crtsys.JustTest.rs01test0406", "0000000101SP", JFinalUtils.DEV);
		if(null != list){
			for(Record rd : list){
				System.out.println( rd.get("org_id") );
				System.out.println( rd.get("app_secret") );
			}
		}
	}
	
}
